package com.itheima.mall.controller.smsController;

import com.itheima.mall.commons.R;
import com.itheima.mall.service.smsService.SmsHomeBrandService;
import com.itheima.pojo.sms.SmsHomeBrand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home")
@CrossOrigin
public class SmsHomeBrandController {
    @Autowired
    private SmsHomeBrandService smsHomeBrandService;

    /**
     * 添加首页推荐品牌
     *homeBrandList
     */
    @PostMapping("/brand/create")
    public R create(@RequestBody List<SmsHomeBrand> homeBrandList) {
        smsHomeBrandService.create(homeBrandList);
        return R.ok("操作成功!");
    }

    /**
     * 批量删除推荐品牌
     *ids
     */
    @PostMapping("/brand/delete")
    public R deleteBrand(@RequestParam("ids") List<Long> ids) {
        smsHomeBrandService.deleteBrand(ids);
        return R.ok("操作成功!");
    }

    /**
     * 分页查询品牌推荐
     * pageNum pageSize brandName recommendStatus
     */
    @GetMapping("/brand/list")
    public R getBrandByPage(@RequestParam(defaultValue = "1") Integer pageNum,
                            @RequestParam(defaultValue = "10") Integer pageSize,
                            String brandName,
                            Integer recommendStatus) {
        return smsHomeBrandService.getBrandByPage(pageNum, pageSize, brandName, recommendStatus);
    }

    /**
     * 批量修改推荐品牌状态
     * ids recommendStatus
     */
    @PostMapping("/brand/update/recommendStatus")
    public R updateBrand(@RequestParam("ids") List<Long> ids, @RequestParam("recommendStatus") Integer recommendStatus) {
        smsHomeBrandService.updateBrand(ids, recommendStatus);
        return R.ok("操作成功!");
    }

    /**
     * 修改推荐品牌排序
     *id sort
     */
    @PostMapping("/brand/update/sort/{id}")
    public R updateSortBrand(@PathVariable("id") Long id, @RequestParam(required = false) Integer sort) {
        smsHomeBrandService.updateSortBrand(id, sort);
        return R.ok("操作成功!");
    }
}
